package com.huawei.eservice;

import com.huawei.eservice.uitls.AppiumUtil;
import com.huawei.eservice.uitls.LogConfiguration;
import com.huawei.eservice.uitls.SelectDriver;

import org.openqa.selenium.WebElement;
import org.testng.ITestContext;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.time.Duration;
import java.util.List;

import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;

public class BasePage {

    private AndroidDriver driver;
    private String platformName;
    private String deviceName;
    private String platformVersion;
    private String appPackage;
    private String appActivity;
    private String serviceUrl;
    private AppiumUtil appiumUtil;
    private SelectDriver selectDriver;

    @BeforeClass
    public void setup(ITestContext context) {
        if (selectDriver == null) {
            LogConfiguration.initLog("LoginPage");
            appiumUtil = new AppiumUtil();
            selectDriver = new SelectDriver();
        }
        selectDriver.selectDriver(context, appiumUtil);
    }

    @Test
    public void plus() throws InterruptedException {
        Thread.sleep(1000);
//        driver.findElementById("com.huawei.ccdc.dev:id/et_login_uid").sendKeys("hwx596568");
//        driver.findElementById("com.huawei.ccdc.dev:id/et_login_pwd").sendKeys("@qq15877151955");
//        driver.findElementById("com.huawei.ccdc.dev:id/btn_login").click();
//        Thread.sleep(3000);
        List<WebElement> imagesList = driver.findElementsByClassName("android.widget.ImageView");
        imagesList.get(4).click();
        Thread.sleep(2000);
        driver.findElementById("com.huawei.ccdc.dev:id/stv_task_remote_inspection").click();

        List<WebElement> tabList = driver.findElementsByClassName("android.support.v7.app.ActionBar$Tab");
        int k = 0;
        while (k < 10) {
            for (int i = 0; i < tabList.size(); i++) {
                tabList.get(i).click();
                Thread.sleep(300);
                for (int j = 0; j < 20; j++) {
                    new TouchAction(driver).press(400, 800).waitAction(Duration.ofMillis(300)).moveTo(400, 200).release().perform();//点击->等待1000毫秒->移动->释放
                }
                for (int j = 0; j < 22; j++) {
                    new TouchAction(driver).press(400, 400).waitAction(Duration.ofMillis(300)).moveTo(400, 1800).release().perform();//点击->等待1000毫秒->移动->释放
                }
            }
            k++;
        }
        System.out.println("1.上下拉刷新");

    }

    public void set() throws InterruptedException {
        Thread.sleep(1000);
        List<WebElement> imagesList = driver.findElementsByClassName("android.widget.ImageView");
        imagesList.get(4).click();
        Thread.sleep(2000);
        driver.findElementById("com.huawei.ccdc.dev:id/stv_task_remote_inspection").click();
        driver.findElementById("com.huawei.ccdc.dev:id/toolBarSave").click();
    }

    @Test
    public void click() throws InterruptedException {
        Thread.sleep(6000);
        while (true) {

            WebElement elementById = driver.findElementById("com.ss.android.ugc.aweme:id/b83");
            for (int i = 0; i < 120; i++) {
                elementById.click();
            }

            Thread.sleep(500);
            driver.findElementById("com.ss.android.ugc.aweme:id/bgp").click();
            Thread.sleep(500);
//        driver.findElementById("com.ss.android.ugc.aweme:id/a0d").sendKeys("你好，点赞0.0");
            driver.findElementById("com.ss.android.ugc.aweme:id/a0d").sendKeys("你好，点赞0.0");
            driver.findElementById("com.ss.android.ugc.aweme:id/a0g").click();
            Thread.sleep(1500);
//            driver.findElementById("com.ss.android.ugc.aweme:id/jp").click();
            new TouchAction(driver).press(400, 400).waitAction(Duration.ofMillis(300)).moveTo(400, 1800).release().perform();//点击->等待1000毫秒->移动->释放
            new TouchAction(driver).press(400, 400).waitAction(Duration.ofMillis(300)).moveTo(400, 1800).release().perform();//点击->等待1000毫秒->移动->释放
            new TouchAction(driver).press(400, 800).waitAction(Duration.ofMillis(300)).moveTo(400, 200).release().perform();//点击->等待1000毫秒->移动->释放
        }
    }


    public void findId() {
    }

    @AfterClass
    public void tearDown() throws Exception {
//        driver.quit();                  //彻底退出程序a
    }

}
